﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim V_XM As String
	Dim V_CH As String
	Dim V_BHID As Int
	Dim V_SQDH As Int
	Dim FSQDH As Int
	Dim FBGData As String
	Dim FIMGList As List
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim wbvJCBG As WebView
	Dim HttpJobTool As HttpJob
	Dim lsvMemu As ListView
	Dim pnlMenu As Panel
	Dim pnlTop As Panel
	Dim lblSM As Label
	Dim btnExit As Button
	Dim pnlView As Panel
	
	Dim HasGetImg As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHJCBGInfo")
	
	Activity.Title = "病人检查报告信息-"  & V_CH & " " &V_XM 
	
	InitLayOut

End Sub

Sub Activity_Resume
	If FSQDH<>V_SQDH Then
		RefreshData
	Else
		wbvJCBG.LoadHtml(FBGData)
	End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitLayOut
	pnlView.Visible = False
	
	lsvMemu.SingleLineLayout.ItemHeight = PublicVar.GV_ListView_ItemHeight * 2
	lsvMemu.SingleLineLayout.Label.TextSize = PublicVar.GV_ListView_TextSize2
	'lsvMemu.ScrollingBackgroundColor = Colors.Black
	
	lblSM.TextSize = PublicVar.GV_ListView_TextSize2 + 2
	btnExit.TextSize = PublicVar.GV_ListView_TextSize2 

End Sub

Sub RefreshData
	Dim sURL,sSession,sBHID,sSQDH,sText As String
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sBHID = PublicVar.GV_DesTool.Base64encrypt(V_BHID)
	sSQDH = PublicVar.GV_DesTool.Base64encrypt(V_SQDH)
	
	sText = "Session=" & sSession & "&BHID=" & sBHID & "&SQDH=" & sSQDH

	sURL = PublicVar.GetServerUrl&"/getbhjcbginfo"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	ProgressDialogShow("正在获取数据，请稍候...")	

End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
			Else If Job.JobName = "Job2" Then
				HttpJobImgSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub

Sub HttpJobSuccess(Job As HttpJob) 
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	If wbvJCBG.IsInitialized Then
		wbvJCBG.LoadHtml(sData)
		FBGData = sData
		FSQDH = V_SQDH
	End If
	
	RefreshImgData
	HasGetImg = False
End Sub

Sub HttpJobError(Job As HttpJob)   
	Dim sMsg As String
	ProgressDialogHide
	
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取检查报告失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
	If KeyCode = KeyCodes.KEYCODE_MENU Then		
		pnlView.Visible = True
		pnlView.BringToFront
		
		Return True
	Else If KeyCode = KeyCodes.KEYCODE_BACK Then
		If pnlView.Visible =True Then
			pnlView.Visible = False
			Return True
		Else
			Return False
		End If
	
	Else
		Return False
	End If
End Sub

Sub SetMenuLayOut(AMenuCount As Int)
	pnlView.Visible = False		
	
	pnlMenu.Height = lsvMemu.SingleLineLayout.ItemHeight * AMenuCount
	pnlMenu.Top = 100%Y - pnlMenu.Height
	
	pnlTop.Height = lsvMemu.SingleLineLayout.ItemHeight 
	
	lsvMemu.Top = pnlTop.Height
	lsvMemu.Height = pnlMenu.Height - lsvMemu.Top
	
	btnExit.Left = pnlTop.Width - btnExit.Width
	btnExit.Height = pnlTop.Height

	lblSM.Height = pnlTop.Height
	lblSM.Width = pnlTop.Width - btnExit.Width

	
End Sub
Sub btnExit_Click
	pnlView.Visible = False

End Sub

Sub pnlView_Click
	pnlView.Visible = False
End Sub

Sub RefreshImgData
	Dim sURL,sSession,sBHID,sSQDH,sText As String
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sBHID = PublicVar.GV_DesTool.Base64encrypt(V_BHID)
	sSQDH = PublicVar.GV_DesTool.Base64encrypt(V_SQDH)
	
	sText = "Session=" & sSession & "&BHID=" & sBHID & "&SQDH=" & sSQDH

	sURL = PublicVar.GetServerUrl&"/getbhjcbgimglist"
	HttpJobTool.Initialize("Job2",Me)
	HttpJobTool.PostString(sURL,sText)
	ProgressDialogShow("正在获取图像数据，请稍候...")	

End Sub

Sub HttpJobImgSuccess(Job As HttpJob) 
	Dim sResult,sCode,sData As String
	Dim mapResult As Map
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取图像数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	PublicVar.GV_JSonTool.Initialize(sData)
	FIMGList = PublicVar.GV_JSonTool.NextArray
	
	SetBHImgList(FIMGList)
End Sub

Sub SetBHImgList(lsRecords As List)
	Dim sLine1,sLine2 As String
	Dim mapResult As Map
	Dim iCount As Int
	lsvMemu.Clear
	
	iCount = lsRecords.Size
	For i = 0 To iCount - 1 
		mapResult = lsRecords.Get(i)
		
		sLine1 = mapResult.Get("STUDYUID")
		sLine2 = mapResult.Get("IMAGETYPE") & " " & mapResult.Get("DATE")
		
		lsvMemu.AddTwoLines2(sLine1,sLine2,mapResult)
		
	Next
	
	lblSM.Text = "共有"&iCount&"张图像"
		
	SetMenuLayOut(3)
	
	HasGetImg = True
End Sub

Sub lsvMemu_ItemClick (Position As Int, Value As Object)
'	Dim elemId As String
'	elemId = Value
	'wbvBLNR.loadUrl("javascript:scrollToElement('" &elemId &"')")
	
	Dim mapReVal As Map
	Dim iJGType As Int
	mapReVal = Value
	
	BHJCBGImgInfo.V_CH = V_CH
	BHJCBGImgInfo.V_XM = V_XM
	BHJCBGImgInfo.V_BHID = V_BHID
	BHJCBGImgInfo.V_SQDH = V_SQDH
	BHJCBGImgInfo.V_ImageIndex = mapReVal.Get("STUDYUID")
	
	StartActivity("BHJCBGImgInfo") 
	
	pnlView.Visible = False
	
End Sub